//
//  MNDOpenDeposAlertViewController.m
//  minidai
//
//  Created by 容贤郁 on 2018/3/15.
//  Copyright © 2018年 迷你金服. All rights reserved.
//

#import "MNDOpenDeposAlertViewController.h"

@interface MNDOpenDeposAlertViewController ()

@property (weak, nonatomic) IBOutlet UIView *alertContainerView;
@property (weak, nonatomic) IBOutlet UIImageView *backgroundImage;

@property (weak, nonatomic) IBOutlet UILabel *alertTitleLabel;
@property (weak, nonatomic) IBOutlet UIImageView *alertIcon;
@property (weak, nonatomic) IBOutlet UIButton *alertLeftButton;
@property (weak, nonatomic) IBOutlet UIButton *alertRightButton;
@property (weak, nonatomic) IBOutlet UILabel *alertDetailLabel;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *detailVerticalConstraint;

@end

@implementation MNDOpenDeposAlertViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.alertContainerView.transform = CGAffineTransformMakeScale(0.2, 0.2);
    
    [self.closeButton addTarget:self action:@selector(closeAlertAction:) forControlEvents:UIControlEventTouchUpInside];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    [UIView animateWithDuration: 0.7
                          delay: 0.0
         usingSpringWithDamping: 0.5
          initialSpringVelocity: 0.1
                        options: UIViewAnimationOptionCurveEaseIn
                     animations: ^{
                         
                         self.alertContainerView.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1.0, 1.0);
                     }
                     completion:^(BOOL finished) {
                         
                     }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}

- (void)setAlertType:(NSString *)alertType {
    //设置交易密码
    if ([alertType isEqualToString:kSetPassword]) {
        
        self.alertTitleLabel.text = @"设置交易密码";
        [self.alertLeftButton setHidden:NO];
        [self.alertRightButton setHidden:NO];
        self.alertDetailLabel.text = @"为了您的账户安全, 网贷产品交易需设置交易密码";
        [self.confirmButton setTitle:@"立即设置" forState:UIControlStateNormal];
        self.alertIcon.image = [UIImage imageNamed:@"open_bank_depository_password_auth"];
    } else {
        self.detailVerticalConstraint.constant = -20;
    }
    
    //缴费授权
    if ([alertType isEqualToString:kSignPayment]) {
        
        self.alertTitleLabel.text = @"缴费授权";
        [self.alertLeftButton setHidden:YES];
        [self.alertRightButton setHidden:YES];
        self.alertDetailLabel.text = @"应合规要求，网贷产品交易前需完成缴费授权";
        [self.confirmButton setTitle:@"立即授权" forState:UIControlStateNormal];
        self.alertIcon.image = [UIImage imageNamed:@"open_bank_depository_payment_auth"];
    }
    
    //设置自动投标授权
    if ([alertType isEqualToString:kSignAutoTender]) {
        
        self.alertTitleLabel.text = @"自动投标授权";
        [self.alertLeftButton setHidden:YES];
        [self.alertRightButton setHidden:YES];
        self.alertDetailLabel.text = @"应合规要求，网贷产品交易前需先完成自动投标授权";
        [self.confirmButton setTitle:@"立即授权" forState:UIControlStateNormal];
        self.alertIcon.image = [UIImage imageNamed:@"open_bank_depository_tender_auth"];
    }
    
    //设置自动投标授权
    if ([alertType isEqualToString:kSignAutoTransfer]) {
        
        self.alertTitleLabel.text = @"债权转让授权";
        [self.alertLeftButton setHidden:YES];
        [self.alertRightButton setHidden:YES];
        self.alertDetailLabel.text = @"应合规要求，网贷产品交易前需先完成债权转让授权";
        [self.confirmButton setTitle:@"立即授权" forState:UIControlStateNormal];
        self.alertIcon.image = [UIImage imageNamed:@"open_bank_depository_transfer_auth"];
    }
    
    //缴费授权已到期
    if ([alertType isEqualToString:kExpiredSignPayment]) {
        
        self.alertTitleLabel.text = @"缴费授权";
        [self.alertLeftButton setHidden:YES];
        [self.alertRightButton setHidden:YES];
        self.alertDetailLabel.text = @"您的缴费授权已到期，为保障您的交易安全，请再次授权";
        [self.confirmButton setTitle:@"立即授权" forState:UIControlStateNormal];
        self.alertIcon.image = [UIImage imageNamed:@"open_bank_depository_payment_auth"];
    }
    
    //自动投标授权已到期
    if ([alertType isEqualToString:kExpiredAutotender]) {
        
        self.alertTitleLabel.text = @"自动投标授权";
        [self.alertLeftButton setHidden:YES];
        [self.alertRightButton setHidden:YES];
        self.alertDetailLabel.text = @"您的缴费授权已到期，为保障您的交易安全，请再次授权";
        [self.confirmButton setTitle:@"立即授权" forState:UIControlStateNormal];
        self.alertIcon.image = [UIImage imageNamed:@"open_bank_depository_tender_auth"];
    }
    
    if (self.alertMessage.length > 0) {
        self.alertDetailLabel.text = self.alertMessage;
    }
}

- (void)setAlertMessage:(NSString *)alertMessage {
    _alertMessage = alertMessage;
    
    self.alertDetailLabel.text = self.alertMessage;
}

- (void)closeAlertAction:(UIButton *)sender {
    [self.view removeFromSuperview];

    [self removeFromParentViewController];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
